Page({
  /**
   * 页面的初始数据
   */
  data: {
    reportTypeArray: ['城区管网', '截污干管', '市政设施'],
    reportType: '城区管网',
    reportIndex: 0,
    all: [
      ['窖井', '雨水管', '排水管道', '排水沟渠', '其他'],
      ['窖井', '支管', '干管', '其他'],
      ['花圃', '人行道', '道路面', '其他'],
    ],
    facilitiesTypeArray: ['窖井', '雨水管', '排水管道', '排水沟渠', '其他'],
    facilitiesType: '窖井',
    facilitiesIndex: 0,
    cover: false,
    QRcode: '',
    picUrl: '',
    picMessage: '',
    focus: '',
    coverText: '',
    textareaShow: true,
    describe: '',
  },
  bindinput: function (e) {
    this.data[e.currentTarget.dataset.val] = e.detail.value;
  },
  fnTextareaInput: function (e) {
    this.setData({
      describe: e.detail.value,
    })
  },
  fnTextereaTap: function () {
    this.setData({
      focus: true,
    })
  },
  reportTypeChange: function (e) {
    let facilitiesTypeArray = this.data.all[e.detail.value]
    this.data.reportType = this.data.reportTypeArray[e.detail.value];
    this.setData({
      facilitiesTypeArray,
      reportIndex: e.detail.value,
      facilitiesIndex: 0
    })
  },
  facilitiesTypeChange: function (e) {
    this.data.facilitiesType = this.data.facilitiesTypeArray[e.detail.value];
    this.setData({
      facilitiesIndex: e.detail.value
    })
  },
  fnQRcodeTap: function () {
    let that = this;
    wx.scanCode({
      success: (res) => {
        let QRcode = res.result;
        QRcode = QRcode.split(',');
        this.data.road = QRcode[0];
        this.data.address = QRcode[1];
        that.setData({
          QRcode,
        })
      },
      fail: (res) => {
        console.log(res)
      }
    })
  },
  fnPicTap: function () {
    let that = this;
    wx.chooseImage({
      count: 3,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        that.setData({
          picMessage: res.tempFilePaths.length,
          picUrl: res.tempFilePaths
        })
      }
    })
  },
  fnBtnTap: function () {
    // console.log(this.data.road)
    // console.log(this.data.address)
    // console.log(this.data.reportType)
    // console.log(this.data.facilitiesType)
    // console.log(this.data.describe)
    // console.log(this.data.contact)
    // console.log(this.data.picMessage)
    if (this.data.road) {
      if (this.data.address) {
        if (this.data.describe) {
          if (this.data.picMessage) {
            this.setData({
              coverText: '提交成功'
            })
            setTimeout(() => {
              this.setData({
                cover: false
              });
              wx.navigateBack({
                delta: 1
              });
            }, 2000);
          } else {
            this.setData({
              coverText: '请上传图片'
            })
          }
        } else {
          this.setData({
            coverText: '请填写问题描述'
          })
        }
      } else {
        this.setData({
          coverText: '请填写详细地址'
        })
      }
    } else {
      this.setData({
        coverText: '请填写所在道路'
      })
    }
    this.setData({
      cover: true,
      textareaShow: false,
    })
    setTimeout(() => {
      this.setData({
        textareaShow: true,
        focus: false,
        cover: false
      });
    }, 2000)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})